package com.thekernel.youdaoyun.testUtil;

import com.thekernel.youdaoyun.YoudaoyunApplication;
import com.thekernel.youdaoyun.bean.Note;
import com.thekernel.youdaoyun.exception.MyException;
import com.thekernel.youdaoyun.exception.impl.DataNotFoundException;
import com.thekernel.youdaoyun.util.FileUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @Author TheKernel
 * @Date 2019/10/02 6:26 下午
 * @Version 1.0
 * @Description 测试 FileUtils
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = YoudaoyunApplication.class)
public class testFileUtils {

    @Test
    public void testCreateFile() throws MyException {
        String content = "Test Content\nKernel";
        FileUtils.createFile(content);
    }

    @Test
    public void testRenameFile() throws MyException {
        Note testNote = new Note();  // 测试 Note
        testNote.setNoteUser(1);
        testNote.setCategory(1);
        testNote.setNoteTitle("newTitle.txt");
        String oldNote = "Title.txt";

//        Assert.assertTrue(FileUtils.renameNote(testNote, oldNote));
    }

    @Test
    public void testDeleteFile() throws MyException {
        Note testNote = new Note();  // 测试 Note
        testNote.setNoteUser(1);
        testNote.setCategory(1);
        testNote.setNoteTitle("newTitle.txt");

//        Assert.assertTrue(FileUtils.deleteNote(testNote));
    }

//    @Test
//    public void testDeleteDir() throws MyException {
//        Note testNote = new Note();  // 测试 Note
//        testNote.setNoteUser(1);
//        testNote.setCategory(1);
//
//        FileUtils.deleteDir(new File(""));
//    }

    @Test
    public void testReadFile() throws DataNotFoundException {
        String filePath = "test.txt";
        System.out.println(FileUtils.readFile(filePath));
    }

}
